import { expect, it } from 'vitest'
import { compress, decompress } from './compression'

it('code should the same after compression and decompression', () => {
  const codes = [
    `console.log('Hello world!');`,
    `console.log('你好世界！');`,
    `
import { render, useRef, useReactive, useComputed } from 'react';
 
function ReactiveComponent() {
  const renderCount = useRef(1).current++;

  const data = useReactive({ count: 1 });
  const countText = useComputed(() => {
    return data.count.get();
  });

  setInterval(() => {
    data.count.set(c => c + 1);
  }, 1000);

  return (
    <div>
      <div>{countText}</div>
      <div>组件渲染次数:{renderCount}</div>
    </div>
  );
}
render(
  <ReactiveComponent />,
  document.getElementById('app')
);

`,
  ]
  codes.forEach((code) => {
    expect(decompress(compress(code))).toBe(code)
  })
})

it('decompress failed should throw error', () => {
  expect(() => {
    decompress('xxxx')
  }).toThrowError('decompress failed')
})
